<?php
namespace App\Http\Middleware;

use Closure;
use Redis;

class ApiTokenCheck
{
    public function handle($request, Closure $next) {
        $token = request()->header('Access-Token','');
        if(!$token){
            return out(777,'token错误！');
        }
        $redis = Redis::connection('public');
        $rootUrl = request()->root();
        $ip = request()->ip();
        $key = 'apiToken'.$rootUrl.$ip;
        $tokenR = $redis->get($key);
        if($token !== $tokenR){
            return out(777,'token错误！');
        }
        return $next($request);
    }
}

